package cn.tedu.ivos2.vehicle.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos2.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos2.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;
    @GetMapping("list")
    public JsonResult list(VehicleQuery vehicleQuery) {
        List<VehicleVO> list = vehicleService.queryVehicleList(vehicleQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult save(VehicleSaveParam vehicleSaveParam) {
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }
    @PostMapping("bind/{vehicleId}/{geofenceId}")
    public JsonResult bind(@PathVariable Long vehicleId, @PathVariable Long geofenceId) {
        vehicleService.bindVehicle(vehicleId, geofenceId);
        return JsonResult.ok();
    }
    @PostMapping("unbind/{vehicleId}")
    public JsonResult unbind(@PathVariable Long vehicleId) {
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }
}
